<template>
	<view id="tmpl" v-show="is_login">
		<view class="profile">
			<view class="left">
				<view class="avatar cu-avatar lg round margin-left">
					<image src="../../static/image/test/avatar.png" mode="widthFix" />
				</view>
				<view class="detail">
					<view class="top">
						<text class="nickname">{{ user.name }}</text>
						<!-- <view class="madal-list">
							<view class="madal-item">
								<image src="../../static/image/test/medal.png" mode="widthFix" />
							</view>
							<view class="madal-item">
								<image src="../../static/image/test/medal.png" mode="widthFix" />
							</view>
						</view> -->
					</view>
					<view class="bottom">{{ user.team }}</view>
					<view class="bottom">{{ user.phone }}</view>
				</view>
			</view>
			<!-- <view class="sign">
				<view class="sign-button">
					<text v-if="sign_01 == 1">已签到</text>
					<text v-else @click="sign_1()">未签到</text>
				</view> -->
				<!-- <view class="qr">
					<image src="../../static/image/icon/qr.png" mode="widthFix" />
				</view> -->
			<!-- </view> -->
		</view>

		<view class="cu-list menu text-left solid-top" style="margin-top: 30upx;">
			<view class="cu-item" :class="'arrow'">
				<view class="content" hover-class="none" @click="emergency()" open-type="redirect">
					<text class="cuIcon-edit text-orange"></text>
					<text class="text-grey">紧急联系人</text>
				</view>
			</view>
			
				<view class="cu-item" :class="'arrow'">
					<view class="content" hover-class="none" @click="emergencys()" open-type="redirect">
						<text class="cuIcon-edit text-orange"></text>
						<text class="text-grey">修改密码</text>
					</view>
				</view>
			

			<view class="cu-item" :class="'arrow'">
				<view class="content" hover-class="none" @click="clearCache()" open-type="redirect">
					<text class="cuIcon-delete text-orange"></text>
					<text class="text-grey">缓存清理</text>
				</view>
			</view>

			<view class="cu-item" :class="'arrow'">
				<view class="content" hover-class="none" @click="JumpKaoshiPage()" open-type="redirect">
					<text class="cuIcon-rank text-orange"></text>
					<text class="text-grey">考试</text>
				</view>
			</view>

			<view class="cu-item" :class="'arrow'">
				<view class="content" hover-class="none" @click="StudyStatistics()" open-type="redirect">
					<text class="cuIcon-calendar text-orange"></text>
					<text class="text-grey">学时统计</text>
				</view>
			</view>

			<view class="cu-item" :class="'arrow'">
				<view class="content" hover-class="none" @click="GetListYinhuan" open-type="redirect">
					<text class="cuIcon-list text-orange"></text>
					<text class="text-grey">隐患查询</text>
				</view>
			</view>

			<view class="cu-item" :class="'arrow'">
				<view class="content" hover-class="none" @click="MessageNews()" open-type="redirect">
					<text class="cuIcon-list text-orange"></text>
					<text class="text-grey">新闻公告<text v-if="show_tip" class="tip cu-tag badge"></text></text>
				</view>
			</view>

			<view class="cu-item" :class="'arrow'">
				<view class="content" hover-class="none" open-type="redirect">
					<text class="cuIcon-activity text-orange"></text>
					<text class="text-grey">关于</text>
				</view>
			</view>
		</view>

		<view class="padding flex flex-direction">
			<button class="cu-btn bg-blue margin-tb-sm lg" @click="out">退出</button>
		</view>
	</view>
</template>

<script>
	import request from '../../static/common/request.js';

	export default {
		data() {
			return {
				is_sign_in: false,
				show_tip: false,
				xxx: '',
				user: {
					name: '',
					phone: '',
					id: 1,
					team: ''
				},
				sign_01: '0',
				qdshId: '',
				code: '100',
				videoPath: '',
				is_login: false
			};
		},
		onLoad() {

		},
		onShow: function() {
			let is_login = uni.getStorageSync('user_token') ? true : false;
			let is_signed = uni.getStorageSync("is_signed") // "1" : "0"\
			this.sign_01 = is_signed
			this.is_login = is_login
			// if (!is_login) {
			// 	uni.navigateTo({
			// 		url: '../profile/user_login'
			// 	});
			// } else {
			this.is_sign_in = uni.getStorageSync('IS_SIGN_IN');
			let _this = this;
			this.$api.user({}).then(res => {
				console.log(res);
				_this.user.name = res.data.data.nickName;
				_this.user.phone = res.data.data.userName;
				_this.user.team = res.data.data.deptName;
			});
			// 	this.sign();
			// }

			this.$api.xwlb({
				beginTime: _this.$_if.GetOfferDate(-1) + " 00:00:00",
				endTime: _this.$_if.GetOfferDate(-1) + " 23:59:59",
			}).then(res => {
				console.log("xwlb" , res)
				_this.show_tip = res.data.rows.length != 0
			})
		},
		methods: {

			// sign(is_show = false) {
			// 	if (this.is_sign_in) {
			// 		// uni.showToast({
			// 		// 	title: '您已签到',
			// 		// 	duration: 2000
			// 		// })
			// 		return false;
			// 	}
			// 	request.globalRequest('/api/index/' + this.user.id, 'GET', {}).then(res => {
			// 		let code = res.data.code;
			// 		if (code === 200) {
			// 			this.is_sign_in = true;
			// 			uni.setStorageSync('IS_SIGN_IN', true);
			// 		}
			// 		uni.showToast({
			// 			title: '签到成功',
			// 			duration: 2000
			// 		});
			// 	});
			// },
			//签到
			sign_1() {
				let _this = this;
				// console.log(this.sign_01)
				// console.log(_this.sign_01)
				this.$api.sign(_this.user.phone).then(res => {
					console.log('[签到]返回值：', res);
					_this.sign_01 = res.data.data.yqd
					uni.setStorageSync("is_signed", _this.sign_01)
					console.log('签到',res)
					uni.showToast({
						title: '签到成功'
					})
				});
			},
			emergency() {
				uni.navigateTo({
					"url": './emergency'
				});
			},
			emergencys(){
				uni.navigateTo({
					url:"./promess"
				})
			},
			JumpKaoshiPage() {
				uni.navigateTo({
					"url": '../other/test_list'
				});
			},
			GetListYinhuan() {
				uni.switchTab({
					"url": '../yinhuan/index'
				});
			},
			MessageNews() {
				uni.navigateTo({
					"url": '../message/mega-news'
				});
			},
			out() {
				uni.clearStorageSync();
				uni.navigateTo({
					url: '../profile/user_login'
				});
			},
			//清理缓存
			clearCache() {
				let token = uni.getStorageSync('user_token');
				let user = uni.getStorageSync('user');
				uni.clearStorageSync();
				uni.setStorageSync('user_token', token);
				uni.setStorageSync('user', user);
				uni.showToast({
					title: '清理成功'
				});
			},
			StudyStatistics() {
				uni.navigateTo({
					url: './study_statistics'
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.mt {
		margin-top: 20upx;
	}

	.container-insert {
		padding: 0 20upx;
	}

	.profile {
		background-color: $background-color-1;
		padding: 20upx;
		@extend .flex-between;

		.left {
			@extend .flex-between;

			.avatar {
				margin-top: 12px;
				margin-left: 0;
				padding-left: 0;

				image {
					width: 100upx;
					height: 100upx !important;
					@extend .image-radis;
				}
			}

			.detail {
				margin-left: 20upx;
				margin-top: 10upx;

				.top,
				.bottom {
					height: 30upx;
					font-size: $uni-font-size-base;
				}

				.top {
					@extend .flex-between;

					.nickname {
						font-size: $font-size-title-2;
					}

					.madal-list {
						margin-left: 10upx;
						@extend .flex-between;
						margin-top: 10upx;

						.madal-item {
							image {
								width: 30upx;
								height: 30upx !important;
							}
						}
					}
				}

				.bottom {
					font-size: $uni-font-size-sm;
					color: #bdbdbd;
					margin-top: 20upx;
				}
			}
		}

		.sign {
			@extend .flex-between;

			.sign-button {
				margin-top: 20upx;
				background-color: $background-color-5;
				color: $font-color-1;
				height: 65upx;
				line-height: 65upx;
				padding: 0 30upx;
				border-radius: 10upx;
			}

			.qr {
				margin-top: 35upx;
				margin-left: 20upx;

				image {
					@extend .icon-image-size;
				}
			}
		}
	}

	.line-group {
		margin-top: 20upx;
		border-bottom: solid 1px #e9e9e9;
	}

	.line-button {
		margin-top: 120upx;
	}

	.tip {
		padding: 0;
		top: 48rpx;
		right: 120upx;
		width: 10rpx;
		height: 10rpx;
	}
</style>
